package
{	
	import starling.display.Button;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.events.Touch;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;
	
	public class PauseDialog extends Sprite
	{
		private var resetBtn:Button;
		private var resumeBtn:Button;
		private var quitBtn:Button;
		private var b1Listener:Function;
		private var b2Listener:Function;
		private var b3Listener:Function;
		
		public function PauseDialog()
		{
			super();
			this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
			resetBtn = new Button(Assets.getUIScreens().getTexture("restart2"));			
			resumeBtn = new Button (Assets.getUIScreens().getTexture("playbtnsmall"));
			quitBtn = new Button(Assets.getUIScreens().getTexture("more"));
			
			addChild(new Image(Assets.getUIScreens().getTexture("pause popup")));
			addChild(resetBtn);
			addChild(resumeBtn);
			addChild(quitBtn);					
		}
		
		protected function onAddedToStage(event:Event):void
		{					
			this.removeEventListener(starling.events.Event.ADDED_TO_STAGE, null);
			resetBtn.addEventListener(starling.events.TouchEvent.TOUCH, function(e:TouchEvent):void
			{
				var touch:Touch = e.getTouch(stage);			
				
				if(touch.phase == TouchPhase.ENDED)
				{				
					b1Listener();
				}				
			});
			resumeBtn.addEventListener(starling.events.TouchEvent.TOUCH, function(e:TouchEvent):void
			{
				var touch:Touch = e.getTouch(stage);			
				
				if(touch.phase == TouchPhase.ENDED)
				{				
					b2Listener();
				}				
			});
			quitBtn.addEventListener(starling.events.TouchEvent.TOUCH, function(e:TouchEvent):void
			{
				var touch:Touch = e.getTouch(stage);			
				
				if(touch.phase == TouchPhase.ENDED)
				{				
					b3Listener();
				}				
			});
			
			resetBtn.x = this.width*0.18;
			quitBtn.x = this.width*0.18;
			resumeBtn.x = this.width*0.64;
			
			
			resetBtn.y = this.height*0.40;
			resumeBtn.y = this.height*0.45;
			quitBtn.y = this.height*0.55;
			
			
		}			
		
		public function setButton1Listener(func:Function):PauseDialog
		{
			b1Listener = func;
			return this;
		}
		
		public function setButton2Listener(func:Function):PauseDialog
		{
			b2Listener = func;
			return this;
		}

		public function setButton3Listener(func:Function):PauseDialog
		{
			b3Listener = func;
			return this;
		}		
	}
}